<template>
    <el-form ref="formRef" :model="form" :rules="rules" label-width="80px">
    <h3 class="title">系统注册</h3>
    <el-form-item label="账号" prop="account">
        <el-input v-model="form.account" placeholder="请输入用户名"></el-input>
    </el-form-item>
    <el-form-item label="密码" prop="password">
         <el-input v-model="form.password" type="password" placeholder="请输入密码"></el-input>
    </el-form-item>
    <el-form-item lable="再次输入密码" prop="cfpassword">
         <el-input v-model="form.cfpassword" type="password" placeholder="再次输入密码"></el-input>    
    </el-form-item>
    <el-form-item lable="">
         <el-button type="primary" class="w100p" @click="register(formRef)">注册</el-button>
    </el-form-item>
    </el-form>
</template>

<script setup>
import router from '@/router';
import {ref} from 'vue'
const formRef =ref()
const form =ref({
    account:"",
    password:"",
    cfpassword:"",
})
const rules = ref({
    account:[
        {required:true, message:"请输入用户名", trigger:["change","blue"]},
        {pattern:/^[a-zA-Z]{6,10}$/,message:'用户名由英文字母组成,长度6-10个字符',trigger:["change","blue"]}
    ],
    password:{
        required:true,
        min:6,
        message:"请输入至少6个字符的密码",
        trigger:["change","bule"],
    },
    cfpassword:[
        {
            required:true,
            message:"再次输入密码",
            trigger:["change","bule"],
        },
        {
            validator:(rule,value,callback) =>{
                console.log('value',value);
                console.log('this.form.password',form.value.password);
                if(value !== form.value.password){
                    callback(new Error("两次输入的密码不一致"));
                }else{
                    callback()
                }
            },
            trigger:["change","blur"],
        },
    ]
})
const register = (formEl) =>{
    
    if(formEl) {
        formEl.validata((valid)=>{
            if(valid){
        
            }
        }) 
    }
   
}
</script>